package sealte.mytable.frame;

import java.awt.BorderLayout;
import java.awt.Dialog;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;

public class Save2DBDialog extends JDialog {
	private static final long serialVersionUID = 2L;
	private MainFrame mf = null;
	private JPanel jp_center = null;
	private JPanel jp_south = null;
	private JPanel jp_content1 = null;
	private JPanel jp_content2 = null;
	private JPanel jp_center_south = null;
	
	private JPanel jp_db_style = null;
	private JPanel jp_db_ip_port = null;
	private JPanel jp_db_name = null;
	private JPanel jp_db_user = null;
	private JPanel jp_db_password = null;
	
	private JLabel jl_db_blank = null;
	private JLabel jl_db_style = null;
	private JLabel jl_db_ip_port = null;
	private JLabel jl_db_name = null;
	private JLabel jl_db_user = null;
	private JLabel jl_db_password = null;
	private JComboBox jcb_db_style = null;
	
	private JTextField jtf_db_ip_port = null;
	private JTextField jtf_db_name = null;
	private JTextField jtf_db_user = null;
	private JPasswordField jpf_db_password = null;
	private JTextArea jta_content = null;
	private JScrollPane jsp_content = null;
	private JButton jb_save = null;
	private JButton jb_cancel = null;
	private TitledBorder tb_center = null;
	private TitledBorder tb_content = null;
	private FlowLayout flowLayout = null;
	private FlowLayout fl_db_style = null;
	private FlowLayout fl_db_ip_port = null;
	private FlowLayout fl_db_name = null;
	private FlowLayout fl_db_user = null;
	private FlowLayout fl_db_password = null;
	
	public Save2DBDialog(MainFrame mf){
		this.mf = mf;
		
		jp_center = new JPanel();
		jp_south = new JPanel();
		jp_content1 = new JPanel();
		jp_content2 = new JPanel();
		jp_center_south = new JPanel();
		jp_db_style = new JPanel();
		jp_db_ip_port = new JPanel();
		jp_db_name = new JPanel();
		jp_db_user = new JPanel();
		jp_db_password = new JPanel();
		
		jl_db_blank = new JLabel("        ");
		jl_db_style = new JLabel("Style:");
		jl_db_ip_port = new JLabel("IP:Port:");
		jl_db_name = new JLabel("Name:");
		jl_db_user = new JLabel("User:");
		jl_db_password = new JLabel("Password:");
		
		jcb_db_style = new JComboBox();
		
		jtf_db_ip_port = new JTextField(35);
		jtf_db_name = new JTextField(35);
		jtf_db_user = new JTextField(35);
		
		jpf_db_password = new JPasswordField(35);
		
		jta_content = new JTextArea(15,40);
		
		jsp_content = new JScrollPane(jta_content);
		
		jb_save = new JButton("Save");
		jb_cancel = new JButton("Cancel");
		
		tb_center = new TitledBorder("DB-Information");
		tb_content = new TitledBorder("Create-Table-Script");
		
		flowLayout = new FlowLayout();
		fl_db_style = new FlowLayout();
		fl_db_ip_port = new FlowLayout();
		fl_db_name = new FlowLayout();
		fl_db_user = new FlowLayout();
		fl_db_password = new FlowLayout();
	}
	
	public void doInit(){
		this.setTitle("Save to DB by SEALTE v0.3");
		this.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
		this.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
		fl_db_style.setAlignment(FlowLayout.LEFT);
		jp_db_style.setLayout(fl_db_style);
		jp_db_style.add(jl_db_blank);
		jp_db_style.add(jl_db_style);
		jcb_db_style.addItem("MySQL");
		jcb_db_style.addItem("Oracle");
		jp_db_style.add(jcb_db_style);
		
		fl_db_ip_port.setAlignment(FlowLayout.RIGHT);
		jp_db_ip_port.setLayout(fl_db_ip_port);
		jp_db_ip_port.add(jl_db_ip_port);
		jp_db_ip_port.add(jtf_db_ip_port);
		
		fl_db_name.setAlignment(FlowLayout.RIGHT);
		jp_db_name.setLayout(fl_db_name);
		jp_db_name.add(jl_db_name);
		jp_db_name.add(jtf_db_name);
		
		fl_db_user.setAlignment(FlowLayout.RIGHT);
		jp_db_user.setLayout(fl_db_user);
		jp_db_user.add(jl_db_user);
		jp_db_user.add(jtf_db_user);
		
		fl_db_password.setAlignment(FlowLayout.RIGHT);
		jp_db_password.setLayout(fl_db_password);
		jp_db_password.add(jl_db_password);
		jp_db_password.add(jpf_db_password);
		
		jp_center_south.setBorder(tb_content);
		jp_center_south.add(jsp_content,BorderLayout.CENTER);
		
		flowLayout.setAlignment(FlowLayout.RIGHT);
		jp_south.setLayout(flowLayout);
		jp_south.add(jb_save);
		jp_south.add(jb_cancel);
		
		jp_content2.setLayout(new BorderLayout());
		jp_content2.add(jp_db_ip_port,BorderLayout.NORTH);
		jp_content2.add(jp_db_name,BorderLayout.CENTER);
		jp_content2.add(jp_db_user,BorderLayout.SOUTH);
		
		jp_content1.setLayout(new BorderLayout());
		jp_content1.setBorder(tb_center);
		jp_content1.add(jp_db_style,BorderLayout.NORTH);
		jp_content1.add(jp_content2,BorderLayout.CENTER);
		jp_content1.add(jp_db_password,BorderLayout.SOUTH);
		
		jp_center.setLayout(new BorderLayout());
		jp_center.add(jp_content1,BorderLayout.CENTER);
		jp_center.add(jp_center_south,BorderLayout.SOUTH);
		
		this.add(jp_center,BorderLayout.CENTER);
		this.add(jp_south,BorderLayout.SOUTH);
		
		this.setLocationRelativeTo(mf);
		this.setResizable(false);
		this.pack();
				
	}

	public JComboBox getJcb_db_style() {
		return jcb_db_style;
	}
	
	public JTextField getJtf_db_ip_port(){
		return jtf_db_ip_port;
	}
	
	public JTextField getJtf_db_name() {
		return jtf_db_name;
	}

	public JTextField getJtf_db_user() {
		return jtf_db_user;
	}

	public JPasswordField getJpf_db_password() {
		return jpf_db_password;
	}

	public JTextArea getJta_content() {
		return jta_content;
	}

	public JButton getJb_save() {
		return jb_save;
	}

	public JButton getJb_cancel() {
		return jb_cancel;
	}
}
